package com.eascs.web.demo.rest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.eascs.app.log.Logger;
import com.eascs.app.log.LoggerFactory;
import com.eascs.site.controller.BaseRestController;
import com.eascs.site.view.BaseRestResult;
import com.eascs.site.view.HtmlRestResult;
import com.eascs.site.view.MessageRestResult;
import com.eascs.site.view.ViewContext;

@Controller
public class SampleBaseRestResultController extends BaseRestController {
	private final Logger logger = LoggerFactory.getLogger(SampleBaseRestResultController.class);

	@RequestMapping(value = "/demo/rest/restdemoform", method = RequestMethod.GET)
	public BaseRestResult<RestDemoForm> restDemoForm(RestDemoForm restDemoForm) {
		return BaseRestResult.buildRestResult(restDemoForm);
	}

	@RequestMapping(value = "/demo/rest/result/buildsuccessresult", method = RequestMethod.GET)
	public Object buildsuccessresult() {
		return BaseRestResult.buildSuccessResult();
	}

	@RequestMapping(value = "/demo/rest/result/messagerestresult", method = RequestMethod.GET)
	public MessageRestResult messagerestresult() {
		return BaseRestResult.buildSuccessResult();
	}

	@RequestMapping(value = "/demo/rest/result/html", method = RequestMethod.GET)
	public HtmlRestResult buildHtmlRestResult() {
		ViewContext.put("data", "testData");
		return new HtmlRestResult("sample/rest/htmlRest");
	}

	@RequestMapping(value = "/demo/rest/result/info", method = RequestMethod.GET)
	public MessageRestResult info() {
		return BaseRestResult.info("hello");
	}

	@RequestMapping(value = "/demo/rest/result/exception", method = RequestMethod.GET)
	public MessageRestResult warnmessageexception() {
		throw new RuntimeException("warnmessageexception");
	}

	@RequestMapping(value = "/demo/rest/result/consumes/xml", method = RequestMethod.GET, consumes = "application/xml")
	public MessageRestResult consumesXml() {
		return BaseRestResult.info("hello");
	}

	@RequestMapping(value = "/demo/rest/result/produces/xml", method = RequestMethod.GET, produces = "application/xml")
	public MessageRestResult producesXml() {
		return BaseRestResult.info("hello");
	}

	@RequestMapping(value = "/demo/rest/result/produces/exception", method = RequestMethod.GET, produces = "application/xml")
	public MessageRestResult exceptionXml() {
		throw new RuntimeException("warnmessageexception");
	}

}